import csv
import pandas as pd
import openpyxl
import os
def csv_to_xlsx_pd():
    csvDir=r'/Users/h/Desktop/评论2'
    files =os.listdir(csvDir)
    suffix = ".csv"
    suffixLength = -len(suffix)
    for file in files:
        if file .endswith(suffix):
            fileAbs =f'{csvDir}/{file}'
            resultFileAbs = f'{csvDir}/{file[:suffixLength]}.xlsx'
            print(fileAbs,resultFileAbs)
            csv = pd.read_csv(fileAbs, encoding='utf-16')
            csv.to_excel(resultFileAbs, sheet_name='data')


if __name__ == '__main__':
    csv_to_xlsx_pd()